#include<bits/stdc++.h>
using namespace std;
struct note{
	int num;
	int yes;
};
int n,k=1;
struct pll{
	int a,b,c,d,e;
};
bool hf1(int m){
	return 0<m&&m<=255;
}
bool hf2(int m){
	return 0<m&&m<=65535;
}
map<string,int>my;
map<string,int>mn;
string str1(int m){
	string str;
	if(m>100)str+=(char)(m/100+'0');
	if(m>10)str+=(char)(m/10%10+'0');
	str+=(char)(m%10+'0');
	return str;
}
string str2(int m){
	string str;
	if(m>10000)str+=(char)(m/10000+'0');
	if(m>1000)str+=(char)(m/1000%10+'0');
	if(m>100)str+=(char)(m/100%10+'0');
	if(m>10)str+=(char)(m/10%10+'0');
	str+=(char)(m%10+'0');
	return str;
}
int main(){
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++){
		string s;
		cin>>s;
		int a,b,c,d,e;
		if(s=="Server"){
			scanf("%d.%d.%d.%d:%d",&a,&b,&c,&d,&e);
			if(hf1(a)&&hf1(b)&&hf1(c)&&hf1(d)&&hf2(e)){
				string ll;
				ll+=str1(a);ll+='.';
				ll+=str1(b);ll+='.';
				ll+=str1(c);ll+='.';
				ll+=str1(d);ll+=':';
				ll+=str2(e);
				cout<<ll<<'\n';	
				if(my[ll]==1){
					cout<<"FAIL\n";
				}
				else {
					my[ll]==1;
					mn[ll]==k;
					k++;
					cout<<"OK\n";
				}
			}
			else {
				cout<<"ERR\n";
			}
		}
		else {
			scanf("%d.%d.%d.%d:%d",&a,&b,&c,&d,&e);
			if(hf1(a)&&hf1(b)&&hf1(c)&&hf1(d)&&hf2(e)){
				string ll;
				ll+=str1(a);ll+='.';
				ll+=str1(b);ll+='.';
				ll+=str1(c);ll+='.';
				ll+=str1(d);ll+=':';
				ll+=str2(e);
				cout<<ll<<'\n';
				cout<<my[ll]<<" "<<mn[ll]<<"\n";		
				if(my[ll]==1){
					cout<<mn[ll]<<"\n";
				}
				else {
					cout<<"FAIL\n";
				}
			}
			else {
				cout<<"ERR\n";
			}
		}
	}
	return 0;
}
